<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>元素的获取</title>
</head>
<body>
<div id="div1">div1</div>
<div id="div2">div2</div>
<div class="cls">div3</div>
<div class="cls">div4</div>
<input type="text" name="username"/>
</body>
<script>
        let id = document.getElementById("div2");
        alert(id);

        let name = document.getElementsByClassName("cls");
        //alert(name.length);

        let tagName = document.getElementsByTagName("div");
        //alert(tagName.length);

        let name1 = document.getElementsByName("username");
        //alert(name1.length);

        let parentElement = id.parentElement;
        //alert(parentElement);
</script>
</html>